package main

import (
    "fmt"
)

func main(){
    c := make(chan int)

    go func(){
        for i := 0; i < 5; i++{
            c <- i
            //向一个关闭的channel发送数据，会包panic错误
            //close(c)
        }

        //关闭channel
        close(c)
    }()

    //如果没有关闭造成deadlock死锁
    for {
        //ok判断close是否关闭
        if data,ok := <-c; ok {
            fmt.Println("data = ",data)
        }else{
            break
        }
    }

    fmt.Println("main Finished..")
}